package com.vvlive.caibao.smartcity.ui;

import android.annotation.SuppressLint;
import android.view.LayoutInflater;
import android.view.View;
import android.view.animation.OvershootInterpolator;
import android.widget.CheckBox;
import android.widget.LinearLayout;

import com.vvlive.caibao.smartcity.base.BaseActivity;
import com.vvlive.caibao.smartcity.utils.InterpolatorUtil;
import com.vvlive.caibao.smartcity.utils.ViewAnimatorUtil;
import com.vvlive.caibao.smartcity.view.CommonActionBar;
import com.vvlive.caibao.smartcity.view.SlideSwitcherView;
import com.vvlive.caibao.smartcity.view.TripleSlideSwitcherView;

import org.kymjs.kjframe.ui.BindView;

import smartcity.vvlive.caibao.com.smartc.R;

/**
 * Created by android on 2015/7/4.
 */
@SuppressLint("NewApi")
public class LightingControlActivity extends BaseActivity implements SlideSwitcherView.OnSlideSwitchListener {
    @BindView(id= R.id.light_control_btn)
    private TripleSlideSwitcherView mTSwitcherView;
   /* private SlideSwitcherView mTSwitcherView;*/
    @BindView(id= R.id.brightness_control)
    private LinearLayout mBrighness_control;
    @BindView(id= R.id.mode_control)
    private LinearLayout mMode_control;
    @BindView(id= R.id.sleep_time)
    private LinearLayout mSleep_time;
    private int width;

    private OvershootInterpolator interpolator;
    @Override
    protected int getContentViewRes() {
        return R.layout.activity_light_control;


    }


    @Override
    public void initWidget() {
        super.initWidget();
        width = this.getWindowManager().getDefaultDisplay().getWidth();
        interpolator = InterpolatorUtil.getOvershootInterpolator();
        CommonActionBar commonActionBar = getCommonActionBar();
        commonActionBar.setTitle(R.string.light_control);
        CheckBox checkBox = new CheckBox(this);
        LayoutInflater inflater =  LayoutInflater.from(this);
        View view = inflater.inflate(R.layout.light_switch,null);
        commonActionBar.setMoreView(view);
        /*android 动画 */
        mTSwitcherView.setOnSlideSwitchListener(this);
        mTSwitcherView.setFirstLabel("灯光控制");
        mTSwitcherView.setSecondLabel("模式控制");
        mTSwitcherView.setThirdLabel("睡眠定时");
        mTSwitcherView.setMoveDuration(260);
        showBrightness();
    }

    @Override
    public void onSlideSwitch(View v, int position) {

        switch (position){
            case 0:
                showBrightness();
                break;
            case 1:
                showMode();
                break;
            case 2:
                showSleeptime();
                break;
            default:
                break;
        }
    }

    private void showBrightness(){

        ViewAnimatorUtil.translate(mMode_control, 500, -width, interpolator).start();
        ViewAnimatorUtil.fade(mMode_control, 0, 500).start();

        ViewAnimatorUtil.translate(mBrighness_control, 500, 0, interpolator).start();
        ViewAnimatorUtil.fade(mBrighness_control, 1, 500).start();



        ViewAnimatorUtil.translate(mSleep_time, 500, -width, interpolator).start();
        ViewAnimatorUtil.fade(mSleep_time, 0, 500).start();




    }

    private void showMode(){
        ViewAnimatorUtil.translate(mMode_control, 500, 0, interpolator).start();
        ViewAnimatorUtil.fade(mMode_control, 1, 500).start();

        ViewAnimatorUtil.translate(mBrighness_control, 500, width, interpolator).start();
        ViewAnimatorUtil.fade(mBrighness_control, 0, 500).start();




        ViewAnimatorUtil.translate(mSleep_time, 500, 0, interpolator).start();
        ViewAnimatorUtil.fade(mSleep_time, 1, 500).start();




    }

    private void showSleeptime(){
        ViewAnimatorUtil.translate(mBrighness_control, 500, width, interpolator).start();
        ViewAnimatorUtil.fade(mBrighness_control, 0, 500).start();


        ViewAnimatorUtil.translate(mMode_control, 500, -width, interpolator).start();
        ViewAnimatorUtil.fade(mMode_control, 0, 500).start();

        ViewAnimatorUtil.translate(mSleep_time, 500, 0, interpolator).start();
        ViewAnimatorUtil.fade(mSleep_time, 1, 500).start();



    }
}
